package com.nny.Demo250;

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class TestMap {
    public void addEmp(Map<String, Emp> map, Emp emp) {
        map.put(emp.getNumber(), emp);
    }

    public void findAllEmp(Map<String, Emp> map) {
        for (Map.Entry<String, Emp> entry : map.entrySet()) {
            System.out.println(entry.getValue());
        }
    }

    public Emp findEmpByName(Map<String, Emp> map, String name) {
        for (Map.Entry<String, Emp> entry : map.entrySet()) {
            if (entry.getValue().getName().equals(name)) {
                return entry.getValue();
            }
        }
        return null;
    }

    public void deleteEmpByNumber(Map<String, Emp> map, String number) {
        map.remove(number);
    }

    public Emp findEmpByNumber(Map<String, Emp> map, String number) {
        return map.get(number);
    }

    public void updateEmpAge(Map<String, Emp> map, String number, int newAge) {
        if (map.containsKey(number)) {
            Emp emp = map.get(number);
            emp.setAge(newAge);
        }
    }
}
